﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="linknews.aspx.cs" Inherits="Admin_News_choose" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../js/jstree/themes/default/style.css" rel="stylesheet" type="text/css" />
    
    <style>
        .hidden
        {
            display: none;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="jsTreeJson" runat="server" CssClass=" hidden">
        </asp:TextBox>
        <div id="jsontree">
        </div>
    </div>
    </form>
    <script src="../../js/jquery1.9.1.js"></script>
    <script src="../../js/jstree/jstree.js" type="text/javascript"></script>
    <script src="../../js/jstree/jstree.checkbox.js" type="text/javascript"></script>
    <script>
        var data = eval('(' + $('#jsTreeJson').val() + ')');
        $(function () {
            $('#jsontree').jstree({
                'plugins': ["wholerow", "checkbox"],
                'core': data,
                'checkbox' : { 
'undetermined' : false, 
'three_state' : false 
},
            });


            $("#jsontree").on("loaded.jstree", function (event, data) {
                // 展开所有节点
                $('#jsontree').jstree('open_all');
                // 展开指定节点
                //data.instance.open_node(1);     // 单个节点 （1 是顶层的id）
                //data.instance.open_node([1, 10]); // 多个节点 (展开多个几点只有在一次性装载后所有节点后才可行）
            });
            $('#jsontree').on("changed.jstree", function (e, data) {
                var selected = [];
                if (data.selected.length > 0) {
                    for (i in data.selected) {
                        var d = {};
                        d.id = data.selected[i].replace(/\D/g, '');
                        d.text = getText(data.selected[i]);
                        selected.push(d);
                    }
                }
                 parent.linknewsselected_node = selected;
               //$('#jsontree').jstree('open_all');
            });
        });

        function getText(id) {
            for (var i in data.data) {
                if (data.data[i].id == id) {
                    return data.data[i].text;
                }
            }
            return '-';
        }
    </script>
</body>
</html>
